package lookas.dao;

import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;

import org.apache.commons.dbcp.BasicDataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class SimpleDao{
    private static final Log  log        = LogFactory.getLog(SimpleDao.class);
    private static DataSource dataSource = setupDataSource();

    public static Connection getConnection() throws SQLException{
        log.debug(("getNumActive>" + ((BasicDataSource)dataSource).getNumActive()));
        log.debug(("getNumActive>" + ((BasicDataSource)dataSource).getNumIdle()));
        return dataSource.getConnection();
    }

    private static DataSource setupDataSource(){
        BasicDataSource ds = new BasicDataSource();
        ds.setDriverClassName("org.apache.derby.jdbc.EmbeddedDriver");
        ds.setUsername("app");
        ds.setPassword("app");
        ds.setUrl("jdbc:derby:db");
        ds.setInitialSize(1);
        ds.setMinIdle(1);
        return ds;
    }
}
